{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2.3. Learning the basics of the distributed version control system Git"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "mkdir myproject\n",
    "cd myproject"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Initialized empty Git repository in\n",
      "~/git/cookbook-2nd/chapter02/myproject/.git/\n"
     ]
    }
   ],
   "source": [
    "git init"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "~/git/cookbook-2nd/chapter02/myproject\n"
     ]
    }
   ],
   "source": [
    "pwd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ".  ..  .git\n"
     ]
    }
   ],
   "source": [
    "ls -a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "git config --global user.name \"My Name\"\n",
    "git config --global user.email \"me@home.com\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "echo \"Hello world\" > file.txt\n",
    "git add file.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[master (root-commit) 02971c0] Initial commit\n",
      " 1 file changed, 1 insertion(+)\n",
      " create mode 100644 file.txt\n"
     ]
    }
   ],
   "source": [
    "git commit -m \"Initial commit\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "commit 02971c0e1176cd26ec33900e359b192a27df2821\n",
      "Author: My Name <me@home.com>\n",
      "Date:   Tue Dec 12 10:50:37 2017 +0100\n",
      "\n",
      "    Initial commit\n"
     ]
    }
   ],
   "source": [
    "git log"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "echo \"Hello world!\" > file.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello world!\n"
     ]
    }
   ],
   "source": [
    "cat file.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "diff --git a/file.txt b/file.txt\n",
      "index 802992c..cd08755 100644\n",
      "--- a/file.txt\n",
      "+++ b/file.txt\n",
      "@@ -1 +1 @@\n",
      "-Hello world\n",
      "+Hello world!\n"
     ]
    }
   ],
   "source": [
    "git diff"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "On branch master\n",
      "Changes not staged for commit:\n",
      "  (use \"git add <file>...\" to update what will\n",
      "      be committed)\n",
      "\n",
      "    modified:   file.txt\n",
      "\n",
      "no changes added to commit (use \"git add\")\n"
     ]
    }
   ],
   "source": [
    "git status"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " file.txt | 2 +-\n",
      " 1 file changed, 1 insertion(+), 1 deletion(-)\n"
     ]
    }
   ],
   "source": [
    "git diff --stat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[master 045df6a] Add exclamation mark to file.txt\n",
      " 1 file changed, 1 insertion(+), 1 deletion(-)\n"
     ]
    }
   ],
   "source": [
    "git commit -am \"Add exclamation mark to file.txt\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "commit 045df6a6f8a62b19f45025d15168d6d7382a8429\n",
      "Author: My Name <me@home.com>\n",
      "Date:   Tue Dec 12 10:59:39 2017 +0100\n",
      "\n",
      "    Add exclamation mark to file.txt\n",
      "\n",
      "commit 02971c0e1176cd26ec33900e359b192a27df2821\n",
      "Author: My Name <me@home.com>\n",
      "Date:   Tue Dec 12 10:50:37 2017 +0100\n",
      "\n",
      "    Initial commit\n"
     ]
    }
   ],
   "source": [
    "git log"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "git clone https://github.com/mylogin/myproject.git"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
